package net.jumpengine.bean;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import net.jumpengine.M;

/**
  * 直线类
 * <br /><br />
 * <b>作者:&nbsp;</b>张天文 <br />
 * <b>日期:&nbsp;</b>2020年9月3日 下午12:12:33<br />
 * @date
 */
public class LineBase extends Base {
	private double x1,y1,x2,y2;
	protected Color color;
	protected int lineWidth=1;
	
	public LineBase(double a,double b,Color color) {
		this(a,b,color,1,0);
	}
	
	/**
	  * 用直线公式y=ax+b, 生成一条基于窗体边界的直线
	 * @param a y=ax+b中的a
	 * @param b y=ax+b中的b
	 * @param color 线条颜色
	 * @param lineWidth 线条宽度
	 * @param index 层级
	 */
	public LineBase(double a,double b,Color color,int lineWidth,int index) {
		super(0,0,0,0,index);
		x1=0;
		y1=a*x1+b;
		x2=M.w();
		y2=a*x2+b;
		this.lineWidth=lineWidth;
		this.color=color;
	}
	
	public LineBase(double x1,double y1,double x2,double y2,Color color) {
		this(x1, y1, x2, y2, color, 1, 0);
	}
	
	public LineBase(double x1,double y1,double x2,double y2,Color color,int lineWidth,int index) {
		super(0,0,0,0,index);
		this.x1=x1;
		this.x2=x2;
		this.y1=y1;
		this.y2=y2;
		this.lineWidth=lineWidth;
		this.color=color;
	}

	@Override
	public void draw(GraphicsContext g) {
		g.setLineWidth(lineWidth);
		g.setStroke(color);
		g.strokeLine(x1, y1, x2, y2);
	}

	public double getX1() {
		return x1;
	}

	public void setX1(double x1) {
		this.x1 = x1;
	}

	public double getY1() {
		return y1;
	}

	public void setY1(double y1) {
		this.y1 = y1;
	}
	
	public void setLoaction1(double x1,double y1) {
		this.x1 = x1;
		this.y1 = y1;
	}

	public double getX2() {
		return x2;
	}

	public void setX2(double x2) {
		this.x2 = x2;
	}

	public double getY2() {
		return y2;
	}

	public void setY2(double y2) {
		this.y2 = y2;
	}
	
	public void setLoaction2(double x2,double y2) {
		this.x2 = x2;
		this.y2 = y2;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public int getLineWidth() {
		return lineWidth;
	}

	public void setLineWidth(int lineWidth) {
		this.lineWidth = lineWidth;
	}
}
